import java.util.LinkedList;

public class MoveZeroes {

    public static void main(String[] args) {
        int[] nums = {2,1};
        new MoveZeroes().moveZeroes(nums);
        System.out.println();
    }

    public void moveZeroes(int[] nums) {
        LinkedList<Integer> queue = new LinkedList<>();
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0 && !queue.isEmpty()) {
                Integer index = queue.poll();
                nums[index] = nums[i];
                nums[i] = 0;
                queue.add(i);
            } else if (nums[i] == 0) {
                queue.add(i);
            }
        }
    }
}
